package usermanager

import org.apache.jasper.compiler.Node.ParamsAction;

import grails.test.*

class ExtJsServiceTests extends GrailsUnitTestCase {
	def extJsService
    protected void setUp() {
        super.setUp()
    }

    protected void tearDown() {
        super.tearDown()
    }

    void testSomething() {
		
		def comp = new Company(id:3,companyName : "testCompany")
		def unit = new Unit(id:1, unitName:"testUnit", companies: comp )
		def proj = new Project(id: 5,projectName: "testProject", units: unit)

		mockDomain(Project, [proj])
		mockDomain(Unit, [unit])
		mockDomain(Company, [comp])
		
		def testLPersons = [ new Person(id: "1",firstName: "testUser1", lastName: "testUser1",projects : proj),
			new Person(id: "2",firstName: "testUser2", lastName: "testUser2", projects: proj),
			new Person(id: "3",firstName: "testUser3", lastName: "testUser3", projects: proj)]
		
		mockDomain(Person, testLPersons)
		
		def extJsControl = mockFor(ExtJsService)
		def testService = new ExtJsService()
		
		String[] param = ["root", " "]
		def items = testService.getTreeData(param)
		assertEquals "testCompany",items[0].text
		
		param=["project","5"]
		items=testService.getTreeData(param)
		assertEquals "testUser1 testUser1",items[0].text
		assertEquals "testUser2 testUser2",items[1].text
		assertEquals "testUser3 testUser3",items[2].text
		
		param=["unit","1"]
		items=testService.getTreeData(param)
		assertEquals "testProject",items[0].text
		
		param=["unit","2"]
		items=testService.getTreeData(param)
		assertEquals items,[]

		param=["company","2"]
		items=testService.getTreeData(param)
		assertEquals items,[]

		param=["company","3"]
		items=testService.getTreeData(param)
		assertEquals "testUnit",items[0].text

    }
}
